package com.cy.pj.activity.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.cy.pj.activity.pojo.Activity;

@Mapper
public interface ActivityDao {
	/**
	 * 查询所有活动信息，一个记录映射为一个Activity对象 1）谁负责与数据库交互（SqlSession，再具体 JDBC API） 2）
	 * 谁负责将ResultSet结果集中的数据取出来存储到Activity？（Mybatis，在具体一点就是 ResultSetHandler）
	 * 
	 * @return
	 */
	@Update("update tb_activity set state=0 where id=#{id}")
	int UpdateState(long id);
	@Select("select * from tb_activity where id=#{id}")
	Activity findById(long id);

	@Select("select * from tb_activity order by createdTime desc")
	List<Activity> findActivities();

	//@Insert(" insert into tb_activity (title,category,startTime,endTime,remark,state,createdTime,createdUser)  values   (#{title},#{category},#{startTime},#{endTime},#{remark},1,now(),#{createdUser})")
	//@Options(useGeneratedKeys = true,keyProperty = "id")
	int insertObject(Activity activity);

	@Delete("delete from tb_activity where id=#{id}")
	int deleteById(long id);

	@Update("update tb_activity set title=#{title},category=#{category},endTime=#{endTime},remark=#{remark},state=#{state},createdUser=#{createdUser} where id=#{id}")
	int updateObject(Activity activity);
}
